//
//  MerchantInfoView.swift
//  ERecycle-Shop
//
//  Created by abb on 16/9/7.
//  Copyright © 2016年 abb. All rights reserved.
//

import UIKit

class MerchantInfoView: UIView {
    
    var user:User? {
        didSet{
            if user != nil {
                iconView.sd_setHighlightedImageWithURL(user!.userImageUrl, options: .RefreshCached)
                nickNameLabel.text = user!.nickName
                phoneNumberLabel.text = user!.phoneNumber
            }
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        backgroundColor = UIColor.tintColor()
    }
    
    
    private func setupUI() {
        addSubview(iconView)
        addSubview(nickNameLabel)
        addSubview(phoneNumberLabel)
        
        iconView.snp_makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.size.equalTo(CGSize(width: 70, height: 70))
            make.centerY.equalTo(self).offset(-10)
        }
        nickNameLabel.snp_makeConstraints { (make) in
            make.top.equalTo(iconView.snp_bottom).offset(10)
            make.centerX.equalTo(self)
        }
        phoneNumberLabel.snp_makeConstraints { (make) in
            make.top.equalTo(nickNameLabel.snp_bottom).offset(10)
            make.centerX.equalTo(self)
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - 懒加载
    /// 头像
    private lazy var iconView:UIImageView = {
        let iv = UIImageView(image: UIImage(named: "user_default"))
        iv.layer.cornerRadius = 35
        iv.layer.masksToBounds = true
        return iv
    }()
    /// 昵称
    private lazy var nickNameLabel:UILabel = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 18)
    /// 电话
    private lazy var phoneNumberLabel:UILabel = UILabel.creatLabel(color: UIColor.blackColor(), fontSize: 16)

}
